<template>
  <div>
    <div class="title">
      <!-- <div class="title0">
        QSMC BGM
        <span style="color:#7eff8c">Feeder</span> Reject Rate Daily RealTime Statistic From 8:00am[由低至高排列]
      </div>
      <div class="titlebottom">
        <div class="title1">Refresh:8</div>
        <div class="title2">[CurrentTime:{{ time }}]</div>
      </div> -->
    </div>
    <div class="line">Line:{{ lineName }} Machine:{{ machineName }}</div>
    <el-table :data="tableData" border style="width: 100%" :header-cell-style="headerStyleEvent" :cell-style="cellStyle"
      :default-sort="{ prop: 'usage', order: 'ascending' }">
      <el-table-column prop="feederId" label="feederId" align="center"></el-table-column>
      <el-table-column prop="feederType" label="feederType" align="center"></el-table-column>
      <el-table-column prop="modulePosition" label="模组位置" align="center"></el-table-column>
      <el-table-column prop="usage" label="抛料率(DPPM)" align="center" sortable></el-table-column>
    </el-table>
  </div>
</template>
<script>
import dayjs from "dayjs";
import { getFeederUsage } from '@/network/nxt'
export default {
  name: 'feeder',
  props: {},
  components: {},
  data() {
    return {
      time: '',
      tableData: [],
      lineName: '',
      machineName: ''
    }
  },
  mounted() {
    this.time = dayjs().format('YYYY-MM-DD HH:mm:ss')
    this.getTableData()
    console.log(this.$route.params.machineId);
  },
  methods: {
    async getTableData() {
      try {
        const startDateTime = dayjs().format('YYYY-MM-DD 08:00:00')
        const endDateTime = this.time
        const res = await getFeederUsage({ startDateTime, endDateTime, MachineId: this.$route.params.machineId })
        console.log(res);
        this.tableData = res.data.usageInfo
        this.lineName = res.data.lineName
        this.machineName = res.data.machineName
      } catch (error) {
        console.log(error);
      }
    },
    headerStyleEvent() {
      return { background: '#eef1f6', color: '#606266' }
    },
    cellStyle({ row, column, rowIndex, columnIndex }) {
      if (columnIndex == 3) {
        if (row.usage < row.usageThreshold) {
          return { backgroundColor: "#92d050" };
        } else if (row.usage >= row.usageThreshold) {
          return { backgroundColor: '#ff0000' }
        }
      }
    },
  }
}
</script>
<style scoped>
.title {
  background-color: #2f2e2e;
  font-size: 23px;
  line-height: 40px;
  color: white;
}

.title0 {
  text-align: center;
}

.titlebottom {
  height: 30px;
  line-height: 30px;
}

.title1 {
  display: inline-block;
  font-size: 16px;
  line-height: 30px;
}

.title2 {
  display: inline-block;
  font-size: 16px;
  line-height: 30px;
  position: absolute;
  left: 50%;
}

.line {
  height: 50px;
  display: flex;
  align-items: center;
  color: #606266;
  font-size: 16px;
  font-weight: 500;
  justify-content: center;
}
</style>